//
//  SignViewController.m
//  MemberProject
//
//  Created by MAC OS X on 15/4/2.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "SignViewController.h"
#import "SignTableViewCell.h"
#import "SignTableHeadView.h"
#import "ZBarSDK.h"
#import "QRCodeGenerator.h"
#import "UIView+CoreGraphics.h"
#import "SignChoiceTableViewCell.h"
#import "MLTableAlert.h"
#import "SignInfoViewController.h"
#import "IQKeyboardManager.h"
#import "LoginViewController.h"
#import "ModelUser.h"
#import "UserInfoManager.h"
#import "SignKnowViewController.h"
#import "SignLabelTableViewCell.h"
#import "DWTagList.h"
#import "SignLabelViewController.h"



@interface SignViewController ()<UITextFieldDelegate,UIScrollViewDelegate,UIAlertViewDelegate,DWTagListDelegate>
{
    SignTableHeadView *headView;
    NSArray *titleArr;//选项名
    NSArray *placeArr;//引导名
    NSArray *nationArr;
    
    
    NSArray *genderArr;//性别
    NSArray *eduLevelArr;//教育选项
    NSArray *userTypeArr;//用户类型选项
    NSArray *politicalStatusArr;//政治面貌选项
    NSArray *seceiveLevelArr;//服务等级选项
    NSArray *severiceTerritoryArr;//意向服务领域选项
    
    
    NSArray *choiceInfoArr;//选择信息
    NSMutableArray *btnTitleArr;//按钮名
    NSMutableArray *sectionTitleArr;//区间名
    NSArray *keyArr;//键值名
    NSMutableDictionary *infoDic;
    BOOL isVolun;//是否为志愿者
    BOOL isAdult;//是否为成年人
    NSString *polState;//政治面貌
    UITextField *editField;//正在编辑
    
    NSMutableArray *seveiceAreaArr;//领域数组
    
    
    
//    NSArray *eduLevelArr;
//    NSArray *userTypeArr;
//    NSArray *politicalStatusArr;
//    AFHTTPRequestOperation *workingOperation;
    CGFloat tagListHeight;
    NSArray *submitKeyArr;

}
@end

@implementation SignViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setupNavigation];
    [self setupData];
    [self setupView];
    

//    [IQKeyboardManager sharedManager].enable = YES;
}
-(void)setupData
{
    titleArr = @[
  @[@"姓名",@"身份证号",@"手机号",@"性别",@"出生年月日",@"籍贯",@"户籍所在地",@"民族",@"最高学历",@"身份",@"是否为志愿者",@"政治面貌"],
  @[@"意向服务领域",@"意向服务地区"],
  @[@"加入志愿者日期",@"志愿者服务号发证单位",@"已有志愿者服务号",@"已服务小时",@"志愿者等级"],
  @[@"组织关系所在单位",@"加入日期",@"职务"],
  @[@"监护人姓名",@"监护人电话"],
  ];
    placeArr = @[
  @[@"请输入姓名",@"请输入身份证号",@"请输入真实手机号",@"",@"",@"",@"",@"",@"",@"",@"",@""],
  @[@"",@""],
  @[@"",@"请输入发证单位",@"请输入已有志愿者服务号",@"0",@""],
  @[@"请输入所在单位",@"",@"请输入职务"],
  @[@"请输入监护人姓名",@"监护人电话"],
  ];
    
//    nationArr = @[@"汉族",@"壮族",@"满族",@"回族",@"苗族",@"维吾尔族",@"土家族",@"彝族",@"蒙古族",@"藏族",@"布依族",@"侗族",@"瑶族",@"朝鲜族",@"白族",@"哈尼族",@"哈萨克族",@"黎族",@"傣族",@"畲族",@"傈僳族",@"仡佬族",@"东乡族",@"高山族",@"拉祜族",@"水族",@"佤族",@"纳西族",@"羌族",@"土族",@"仫佬族",@"锡伯族",@"柯尔克孜族",@"达斡尔族",@"景颇族",@"毛南族",@"撒拉族",@"布朗族",@"塔吉克族",@"阿昌族",@"普米族",@"鄂温克族",@"怒族",@"京族",@"基诺族",@"德昂族",@"保安族",@"俄罗斯族",@"裕固族",@"乌兹别克族",@"门巴族",@"鄂伦春族",@"独龙族",@"塔塔尔族",@"赫哲族" ,@"珞巴族"];
    
    NSString *jsonpath=[[NSBundle mainBundle]pathForResource:@"nations" ofType:@"json"];
    NSData *data=[NSData dataWithContentsOfFile:jsonpath];
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    nationArr = json[@"nationlist"];
    
    
    
    
    genderArr = @[@"男",@"女"];
    eduLevelArr = @[@"05-小学",@"06-初中",@"07-高中",@"09-大专",@"10-本科",@"11-硕士",@"12-博士",@"02-博士以上"];
    userTypeArr = @[@"学生",@"在职",@"农民",@"军人",@"人民武装警察"];
    politicalStatusArr=@[@"团员",@"预备党员",@"党员",@"其它",@"党员（保留团籍）"];
    seceiveLevelArr =@[@"0",@"1",@"2",@"3",@"4",@"5"];
    severiceTerritoryArr = @[@"扶贫济困",@"助老助残",@"社区服务",@"生态建设",@"大型活动",@"抢险救灾",@"网络文明",@"社会管理",@"文化建设",@"西部开发",@"海外服务"];
    
//    seveiceAreaArr =[NSMutableArray new];
    [self getSize];
    isVolun = NO;
    isAdult = YES;
    /*
     userName,姓名
     idNumber,身份证号
     loginMobile,手机号
     nprovince,籍贯省
     ncity,籍贯市
     regProvince,户籍所在地-省
     regCity,户籍所在地-市
     regDistrict,户籍所在地-区
     nationality,民族
     eduLevel,最高学历
     userType,身份
     voluteerFlag,是否为志愿者
     politicalStatus,政治面貌
     
     cylcUnit，团组织关系所在单位
     clycJoinDate
     
     @"bestEdu",@"",//最高学历
     @"guarderName",@"",//监护人姓名
     */

    
    
keyArr=@[
@[@"userName",@"certificateNo",@"loginMobile",@"gender",@"birthday",@"birthPlace",@"regPlace",@"nationality",@"eduLevel",@"userType",@"volunteerFlag",@"politicalStatus"],
  @[@"severiceTerritory",@"serviceLocation"],
  @[@"joinVolunteerDate",@"volunteerIssuse",@"volunteerNo",@"volunteerServiceHours",@"volunteerLevel"],
  @[@"groudUnit",@"groudJoinDate",@"groudPost"],
  @[@"guardianName",@"guardianMobile"],
];
    
    
    //按钮
    NSMutableArray *arr1 = [NSMutableArray arrayWithObjects:@"",@"",@"",@"性别",@"出生年月日",@"请选择籍贯",@"请选择户籍所在地",@"民族",@"请选择最高学历",@"请选择身份",@"",@"请选择政治面貌", nil];
    NSMutableArray *arr2 = [NSMutableArray arrayWithObjects:@"请选择意向服务领域",@"请选择意向服务地区", nil];
    NSMutableArray *arr3 = [NSMutableArray arrayWithObjects:@"请选择加入志愿者日期",@"",@"",@"",@"0", nil];
    NSMutableArray *arr4 = [NSMutableArray arrayWithObjects:@"",@"请选择加入日期",@"", nil];
    NSMutableArray *arr5 = [NSMutableArray arrayWithObjects:@"",@"", nil];
    btnTitleArr = [NSMutableArray arrayWithObjects:arr1,arr2,arr3,arr4,arr5, nil];
    infoDic = [NSMutableDictionary new];
    for (int i=0; i<keyArr.count; i++) {
        NSArray *arr = keyArr[i];
        for (int j=0; j<arr.count; j++) {
            [infoDic setValue:@"" forKey:arr[j]];
        }
    }
    //区标题
    sectionTitleArr = [NSMutableArray arrayWithObjects:@"用户基本信息(必填)",@"服务相关信息",@"志愿者相关信息",@"团员/党员基本信息(必填)",@"监护人信息(必填)", nil];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleNotification:)
                                                 name:SVProgressHUDDidTouchDownInsideNotification
                                               object:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [IQKeyboardManager sharedManager].enable = NO;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:SVProgressHUDDidTouchDownInsideNotification object:nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager.operationQueue cancelAllOperations];
}
#pragma mark 点击取消等待界面
- (void)handleNotification:(NSNotification *)notif
{
    [SVProgressHUD dismiss];
    [self.workingOperation cancel];
}
-(void)setupView
{
    UIView *headBackgroundView = [[UIView alloc]init];
    
    headView = [[SignTableHeadView alloc]init];
    [headView setupView];
    CGFloat height = [self showQRImg];
    
    headView.frame = CGRectMake(0, 2, SCREEN_WIDTH-6, height);
    headView.titleLabel.frame = CGRectMake(10,0,SCREEN_WIDTH-20, height);
    [headBackgroundView addSubview:headView];
    
    headBackgroundView.frame =CGRectMake(0, 0, SCREEN_WIDTH, headView.height +10) ;
    self.mainTableView.tableHeaderView = headBackgroundView;
    
    UIView *footBackgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120)];
    
    self.mainTableView.tableFooterView = footBackgroundView;
    
    
    UIView *knowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 20)];
    UIButton *knowBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [knowBtn addTarget:self action:@selector(confirmSign:) forControlEvents:64];
    
    
    UIButton *clickBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
    [clickBtn setTitle:@"注册须知" forState:0];
    [clickBtn setTitleColor:[UIColor colorWithRed:88/255.0 green:196/255.0 blue:181/255.0 alpha:1] forState:0];
    
    [clickBtn addTarget:self action:@selector(clickKnowSign:) forControlEvents:64];
    [knowView addSubview:clickBtn];
//    [knowView addSubview:knowBtn];
    
    
    UIButton *submitBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 30,SCREEN_WIDTH-6 ,40)];
    [submitBtn setTitle:@"提交" forState:0];
    [submitBtn addTarget:self action:@selector(submitAction) forControlEvents:64];
    [submitBtn setTitleColor:[UIColor whiteColor] forState:0];
    submitBtn.layer.cornerRadius = 5;
    [submitBtn setBackgroundColor:[UIColor colorWithRed:0 green:102.0f/255.0f blue:101.0f/255.0f alpha:1]];
    [footBackgroundView addSubview:submitBtn];
    [footBackgroundView addSubview:knowView];
    
    [self.mainTableView registerNib:[UINib nibWithNibName:@"SignTableViewCell" bundle:nil] forCellReuseIdentifier:@"cellStr"];
    
    
}

#pragma mark 点击注册须知
-(void)confirmSign:(UIButton *)sender
{
    
}
#pragma mark 查看注册须知
-(void)clickKnowSign:(UIButton *)sender
{
    SignKnowViewController *signKnowVC = [[SignKnowViewController alloc]initWithNibName:@"SignKnowViewController" bundle:nil];
    [self.navigationController pushViewController:signKnowVC animated:YES];
}
#pragma mark 提交
-(void)submitAction
{
    BOOL isNeedWrite = [self isNeedWritePolicalState];
    
    CSResultBlock result = ^(NSString *str)
    {
        [Utils showAlert:[NSString stringWithFormat:@"%@不能为空",str]];
    };
    
    for (int section=0; section<keyArr.count; section++) {
        NSArray *arr = keyArr[section];
        for (int row=0; row<arr.count; row++) {
            NSString *key = arr[row];
            NSString *value = [infoDic valueForKey:key];
            
            //如果不是志愿者，清空该信息
            if (isVolun==NO&&section==2) {
                    [infoDic setValue:@"" forKey:key];
                    break;
            }
            if (isVolun==YES&&section==2&&(row==3||row==4)) {
                if ([infoDic[key] isEqualToString:@""]) {
                    value=@"0";
                    [infoDic setValue:value forKey:key];
                }
            }
            
            
            
            if (isVolun==NO&&section==0) {
                if(row==10)
                {
                    [infoDic setValue:@"0" forKey:key];
                    value = @"0";
                }
                
            }

//            如果不是团员，清空该信息
            if (!isNeedWrite&&section==3) {
                [infoDic setValue:@"" forKey:key];
                break;
            }
            //如果是成年人,清空该信息
            if (isAdult==YES&&section==4) {
                [infoDic setValue:@"" forKey:key];
                break;
            }
            
            
            if (section!=1) {
                
                //没有填
                if ([value isEqualToString:@""]) {
                    if (section==0&&(row==3||row==4)) {
                        
                    }else
                    {
                        result(titleArr[section][row]);
                        return;
                    }
                        
                    
                    
                    
                }else
                {
                    if (section==0&&row==1)
                    {
                        if (![Utils validateIdCard:value]) {
                            [self showAlert:@"请正确输入您的身份证号码"];
                            return;
                        }
                    }
                    if (section==0&&row==2)
                    {
                        if (![Utils validateMobile:value]) {
                            [self showAlert:@"手机号格式不对"];
                            return;
                        }
                    }
                    if (section==4&&row==1) {
                        if (![Utils validateMobile:value]) {
                            [self showAlert:@"监护人手机号格式不对"];
                            return;
                        }
                    }
                    
                    
                    
                }
            }

            
        
            
        }
    }
    //验证身份证号跟电话号码
    if ([self checkIdNumAndLoginMobile]) {
        //    提交
        [self submitInfo];
    }
}
-(BOOL)checkIdNumAndLoginMobile
{
    return 1;
}
#pragma mark 把原先infoDic处理成要上传的dic
-(NSMutableDictionary *)handleSubmitDic
{
    submitKeyArr = @[
                              @"userName",
                              @"certificateNo",
                              @"loginMobile",
                              @"gender",
                              @"birthday",
                              @"birthPlace",
                              @"regPlace",
                              @"nationality",
                              @"eduLevel",
                              @"userType",
                              @"volunteerFlag",
                              @"politicalStatus",
                              @"severiceTerritory",
                              @"serviceLocation",
                              @"joinVolunteerDate",
                              @"volunteerIssuse",
                              @"volunteerServiceHours",
                              @"volunteerNo",
                              @"volunteerLevel",
                              @"cylcUnit",
                              @"joinClycDate",
                              @"clycPost",
                              @"partyUnit",
                              @"joinPartyDate",
                              @"partyPost",
                              @"guardianName",
                              @"guardianMobile"
                              ];

    NSMutableDictionary *submitDic = [NSMutableDictionary new];
    for (int i=0; i<submitKeyArr.count; i++) {
        [submitDic setValue:@"" forKey:submitKeyArr[i]];
    }
    for (NSString *key in infoDic.allKeys) {
        if ([submitDic.allKeys containsObject:key]) {
            if (![infoDic[key] isEqualToString:@""]) {
                [submitDic setValue:infoDic[key] forKey:key];
            }
        }
    }
    
    //政治面貌
    NSString *pState = infoDic[@"politicalStatus"];
    if ([pState isEqualToString:@"团员"]) {
        [submitDic setValue:infoDic[@"groudUnit"] forKey:@"cylcUnit"];
        [submitDic setValue:infoDic[@"groudJoinDate"] forKey:@"joinClycDate"];
        [submitDic setValue:infoDic[@"groudPost"] forKey:@"clycPost"];

    }else if([pState isEqualToString:@"党员"]||[pState isEqualToString:@"预备党员"])
    {
        
        [submitDic setValue:infoDic[@"groudUnit"] forKey:@"partyUnit"];
        [submitDic setValue:infoDic[@"groudJoinDate"] forKey:@"joinPartyDate"];
        [submitDic setValue:infoDic[@"groudPost"] forKey:@"partyPost"];
    }
    //性别
    NSString *gender = infoDic[@"gender"];
    if ([gender isEqualToString:@"男"]) {
        [submitDic setValue:@"1" forKey:@"gender"];
    }else if([gender isEqualToString:@"女"])
    {
        [submitDic setValue:@"2" forKey:@"gender"];
    }
    
    
    
    //最高学历转换为数字
    NSString *eduLevel = infoDic[@"eduLevel"];
    if ([eduLevelArr containsObject:infoDic[@"eduLevel"]]) {
        for (int i=0; i<eduLevelArr.count; i++) {
            NSString *str = eduLevelArr[i];
            if ([str isEqualToString:eduLevel]) {
                [submitDic setValue:[NSString stringWithFormat:@"%d",i+1] forKey:@"eduLevel"];
            }
        }

    }
    //身份
    NSString *userType = infoDic[@"userType"];
    if ([userTypeArr containsObject:userType]) {
        for (int i=0; i<userTypeArr.count; i++) {
            NSString *str = userTypeArr[i];
            if ([str isEqualToString:userType]) {
                [submitDic setValue:[NSString stringWithFormat:@"%d",i+1] forKey:@"userType"];
            }
        }
    }
    //政治面貌
    NSString *politicalStatus = infoDic[@"politicalStatus"];
    if ([politicalStatusArr containsObject:politicalStatus]) {
        for (int i=0; i<politicalStatusArr.count; i++) {
            NSString *str = politicalStatusArr[i];
            if ([str isEqualToString:politicalStatus]) {
                [submitDic setValue:[NSString stringWithFormat:@"%d",i] forKey:@"politicalStatus"];
            }
        }
        
    }
    //志愿者等级
    NSString *volunteerLevel = infoDic[@"volunteerLevel"];
    if ([volunteerLevel isEqualToString:@""]) {
        [submitDic setValue:@"0" forKey:@"volunteerLevel"];
        
    }
//    //志愿者服务领域
//    NSString *severiceTerritory = @"";
//    if (seveiceAreaArr.count>0) {
//        severiceTerritory = [seveiceAreaArr componentsJoinedByString:@","];
//        [submitDic setValue:severiceTerritory forKey:@"severiceTerritory"];
//    }
    
    //志愿者服务时间
    NSString *volunteerServiceHours = infoDic[@"volunteerServiceHours"];
    if ([volunteerServiceHours isEqualToString:@""]) {
        [submitDic setValue:@"0" forKey:@"volunteerServiceHours"];
        
    }
    return submitDic;
}
-(NSString *)changeDateFormat:(NSString *)date
{
    if ([date isKindOfClass:[NSString class]]&&![date isEqualToString:@""]) {
        NSArray *arr = [date componentsSeparatedByString:@"-"];
        NSString *newDate = @"";
        for (int i=0; i<arr.count; i++) {
            newDate = [NSString stringWithFormat:@"%@%@",newDate,arr[i]];
        }
        
        return newDate;
    }else
        return date;
    
}

-(void)submitInfo
{
//    Voluteer
//    checkExistsIdNo//身份证
//
//    checkExistsUserId//手机号码
//    verifyVoluteerLogin//
//
//    findVolunteerByTelNo
//
//    loadVoluteer
    __block CSVoidBlock loginResult = ^(void)
    {
        NSMutableDictionary *dic = [self handleSubmitDic];
        NSString *telNum = dic[@"loginMobile"];
        NSString *sendTelNum =[[BuaatVolunteerServerSDK sharedInstance]encryptStrWithPublicKey:telNum] ;
        
        NSString *pdStr = [telNum substringFromIndex:telNum.length-6];
        NSString *pdMD5Str = [Utils md5:pdStr];
        
        NSString *userType = dic[@"userType"];
        NSString *userName = dic[@"userName"];
        NSString *certificateType = @"CID";
        NSString *idStr = dic[@"certificateNo"];
        
        NSString *certificateNo =[[BuaatVolunteerServerSDK sharedInstance]encryptStrWithPublicKey:[idStr uppercaseString]];
        NSString *gender = dic[@"gender"];
        NSString *birthday = dic[@"birthday"];
    
        NSString *birthPlace = dic [@"birthPlace"];
        NSString *regPlace = dic[@"regPlace"];
        NSString *nationality = dic[@"nationality"];
        NSString *eduLevel = dic[@"eduLevel"];
        NSString *politicalStatus = dic [@"politicalStatus"];
        NSString *cylcUnit = dic [@"cylcUnit"];
        
        NSString *clycPost = dic[@"clycPost"];
        NSString *joinClycDate = dic[@"joinClycDate"];
        NSString *partyUnit = dic[@"partyUnit"];
        NSString *joinPartyDate = dic[@"joinPartyDate"];
        NSString *partyPost = dic [@"partyPost"];
        NSString *joinVolunteerDate = dic[@"joinVolunteerDate"];
        NSString *volunteerIssuse = dic[@"volunteerIssuse"];
        NSString *volunteerServiceHours = dic[@"volunteerServiceHours"];
        NSString *volunteerLevel = dic [@"volunteerLevel"];
        NSString *volunteerNo = dic [@"volunteerNo"];
        
        NSString *volunteerFlag = dic [@"volunteerFlag"];
        NSString *severiceTerritory = dic[@"severiceTerritory"];
        NSString *serviceLocation = dic[@"serviceLocation"];
        NSString *guardianName = dic[@"guardianName"];
        NSString *guardianMobile = [[BuaatVolunteerServerSDK sharedInstance]encryptStrWithPublicKey:dic [@"guardianMobile"]];
        
        
        
        joinVolunteerDate = [self changeDateFormat:joinVolunteerDate];
        joinPartyDate = [self changeDateFormat:joinPartyDate];
        joinClycDate = [self changeDateFormat:joinClycDate];
        birthday = [self changeDateFormat:birthday];
        [SVProgressHUD showWithStatus:@"正在注册" maskType:SVProgressHUDMaskTypeBlack];
        
        [[BuaatVolunteerServerSDK sharedInstance]requestVolunteerRegisterWithGroupCode:self.groupCode
    loginMobile:sendTelNum
    loginPasswd:pdMD5Str
    userType:userType
    userName:userName
    gender:gender
    birthday:birthday
    certificateType:certificateType
    certificateNo:certificateNo
    birthPlace:birthPlace
    regPlace:regPlace
    nationality:nationality
    eduLevel:eduLevel
    politicalStatus:politicalStatus
    cylcUnit:cylcUnit
    clycPost:clycPost
    joinClycDate:joinClycDate
    partyUnit:partyUnit
    joinPartyDate:joinPartyDate
    partyPost:partyPost
    joinVolunteerDate:joinVolunteerDate
    volunteerIssuse:volunteerIssuse
    volunteerServiceHours:volunteerServiceHours
    volunteerLevel:volunteerLevel
    volunteerNo:volunteerNo
    volunteerFlag:volunteerFlag
    severiceTerritory:severiceTerritory
    serviceLocation:serviceLocation
    guardianName:guardianName
    guardianMobile:guardianMobile
    success:^(NSHTTPURLResponse *response, id responseObject) {
        [SVProgressHUD dismiss];
        if ([responseObject isKindOfClass:[NSDictionary class]])
        {
            id ret = responseObject[@"ret"];
            NSLog(@"%@",responseObject[@"msg"]);
            if ([ret isKindOfClass:[NSNumber class]]) {
                NSNumber *num = ret;
                if (num.intValue==0) {
                    [self pushLogin];
                    
                }else if(num.intValue==1203)
                {
                    [SVProgressHUD showErrorWithStatus:@"该身份证号已注册" maskType:SVProgressHUDMaskTypeBlack];
                }
                else
                {
                    [SVProgressHUD showErrorWithStatus:@"该手机号已注册" maskType:SVProgressHUDMaskTypeBlack];
                }
            }
        }
        else
        {
            [SVProgressHUD showErrorWithStatus:@"注册失败" maskType:SVProgressHUDMaskTypeBlack];
        }
        
        
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
    }];
    };
    loginResult();
//        //身份证
//    CSVoidBlock idResult = ^(void)
//    {
//        NSDictionary *telNoParameters = @{@"token":@"sdfsadfsadfasdf",@"module":@"Voluteer",@"method":@"checkExistsIdNo",@"requestId":[NSNull new],@"requestParam":@[infoDic[@"idNumber"]]};
//        
//        //身份证号验证
//        self.workingOperation = [Utils requestDic:telNoParameters andRusult:^(id result) {
//            if (result&&[result isKindOfClass:[NSDictionary class]]) {
//                NSDictionary *dic = (NSDictionary *)result;
//                NSNumber *num = dic[@"responseData"];
//                if (num.intValue==0) {
//                    loginResult();
//                }else
//                {
//                    [SVProgressHUD showErrorWithStatus:@"该身份证号已注册" maskType:SVProgressHUDMaskTypeBlack];
//                }
//            }else
//            {
//                [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
//            }
//        } andError:^(id result) {
//            [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
//        }];
//    };
//    
//    //手机号
//    [SVProgressHUD showWithStatus:@"注册中。。" maskType:SVProgressHUDMaskTypeBlack];
//    NSDictionary *telNoParameters = @{@"token":@"sdfsadfsadfasdf",@"module":@"Voluteer",@"method":@"checkExistsUserId",@"requestId":[NSNull new],@"requestParam":@[infoDic[@"loginMobile"]]};
//    
//    //手机号验证
//    self.workingOperation = [Utils requestDic:telNoParameters andRusult:^(id result) {
//        if (result&&[result isKindOfClass:[NSDictionary class]]) {
//            NSDictionary *dic = (NSDictionary *)result;
//            NSNumber *num = dic[@"responseData"];
//            if (num.intValue==0) {
//                idResult();
//            }else
//            {
//                [SVProgressHUD showErrorWithStatus:@"该手机号已注册" maskType:SVProgressHUDMaskTypeBlack];
//            }
//        }else
//        {
//            [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
//        }
//    } andError:^(id result) {
//        [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
//    }];
    
    
    
    
}
-(void)pushLogin
{
    UIAlertView *aView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"注册成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [aView show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)showAlert:(NSString *)alertTitle
{
    UIAlertView *aView = [[UIAlertView alloc]initWithTitle:@"警告" message:alertTitle delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [aView show];
}
#pragma mark 生成二维码
-(CGFloat)showQRImg
{
//       UIImage *img =[QRCodeGenerator qrImageForString:_zbarStr imageSize:headView.barImageView.height];
//        [headView.barImageView setImage:img];
    headView.titleLabel.text = self.groupName;
    CGFloat height = [Utils heightForLabel:self.groupName andFont:18 andWidth:SCREEN_WIDTH-40];
    
    
    return height+40-21;
}

-(void)setupNavigation
{
    self.navigationController.navigationBar.barStyle=UIBarStyleDefault;
    
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 25)];
    [backBtn setTitle:@"返回" forState:0];
    [backBtn setTitleColor:[UIColor whiteColor] forState:0];
    [backBtn addTarget:self action:@selector(dismissBack) forControlEvents:64];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    
//    [self titleWithLabel:@"注册" andColor:nil];
    self.title = @"注册";
    
}
-(void)getSize
{
    float total =  SCREEN_WIDTH-80-20-15;
    int count =(int)total/60;
    int totalCount =((int)seveiceAreaArr.count+1);
    int height = totalCount/count;
    int needAdd =totalCount%count;
    if (needAdd==0) {
        needAdd = 0;
    }else
        needAdd = 1;
    
    tagListHeight = 30.0*(height+needAdd)+10;
//    if (tagListHeight<44) {
//        tagListHeight=44;
//    }

}
-(void)dismissBack
{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    switch (section) {
        case 0:
        case 1:return 30;
            break;
            case 2:
            return isVolun?30:0;
            break;
        case 3:{
            if ([self isNeedWritePolicalState]) {
                return 30;
            }else return 0;
        }
            break;
        case 4:
        {
            if (!isAdult) {
                return 30;
            }
        }
            break;
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        case 1:
            return 44;
            break;
        case 2:
            return isVolun?44:0;
            break;
        case 3:{
            
            if ([self isNeedWritePolicalState]) {
                return 44;
            }else return 0;
        }
            break;
            case 4:
        {
            if (!isAdult) {
                return 44;
            }
        }
            break;
    }
    return 0;
}
#pragma mark 是不是团员
-(BOOL)isNeedWritePolicalState
{
    NSString *str =infoDic[@"politicalStatus"];
    return (![str isEqualToString:@"其它"]&&![str isEqualToString:@""])?YES:NO;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//    UIView *sectionHeadView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.width, 30)];
    titleLabel.backgroundColor = [UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1];
    titleLabel.font = [UIFont systemFontOfSize:17];
    titleLabel.text = sectionTitleArr[section];
//    titleLabel.clipsToBounds = YES;
    if (section==0) {
        //画上圆角
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:titleLabel.bounds      byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight    cornerRadii:CGSizeMake(10,10)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = titleLabel.bounds;
        maskLayer.lineWidth = 5;
        
        maskLayer.strokeColor = titleLabel.backgroundColor.CGColor;
        maskLayer.path = maskPath.CGPath;
        titleLabel.layer.mask = maskLayer;
    }
    return titleLabel;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return sectionTitleArr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *mArr = titleArr[section];
    return mArr.count;
}
//    - (void)selectedTag:(NSString *)tagName tagIndex:(NSInteger)tagIndex
//{
//    
//    if (tagIndex==seveiceAreaArr.count) {
//        SignLabelViewController *signLabelVC = [[SignLabelViewController alloc]initWithNibName:@"SignLabelViewController" bundle:nil];
//        [signLabelVC setSelectArr:seveiceAreaArr];
//        [signLabelVC backAction:^(NSMutableArray *mArr) {
//            seveiceAreaArr = mArr;
//            [self getSize];
//            [self.mainTableView reloadData];
//        }];
//         [self.navigationController pushViewController:signLabelVC animated:YES];
////        [seveiceAreaArr addObject:@"恩恩恩恩"];
////
////
////        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
////        [self.mainTableView beginUpdates];
////        [self.mainTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
////        [self.mainTableView endUpdates];
//        
//    }else{
//        
//        [seveiceAreaArr removeObjectAtIndex:tagIndex];
//        [self getSize];
//        [self.mainTableView reloadData];
////        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
////        [self.mainTableView beginUpdates];
////        [self.mainTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
////        [self.mainTableView endUpdates];
//    }
//}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

        SignTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellStr" forIndexPath:indexPath];
        
        //    if (!cell) {
        //        cell=[[[[NSBundle mainBundle] loadNibNamed:@"SignTableViewCell" owner:self options:nil] lastObject]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellStr"];
        //    }
        //    cell.contentView.userInteractionEnabled =NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.contentLabel.tag = 10*indexPath.section+indexPath.row;
        cell.contentLabel.text = titleArr[indexPath.section][indexPath.row];
        cell.contentLabel.hidden = NO;
        CGSize size = [cell.contentLabel sizeThatFits:CGSizeMake(320, 20)];
        CGFloat titleWidth = size.width;
        if (titleWidth<60) {
            titleWidth =60;
        }
        cell.titleWidth.constant = titleWidth;
        cell.contentDistance.constant = titleWidth+5;
        cell.contentField.adjustsFontSizeToFitWidth = YES;
        
        CSVoidBlock noHideBlock = ^(void)
        {
            NSString *placeStr = placeArr[indexPath.section][indexPath.row];
            if ([placeStr isEqualToString:@""]) {
                //选择项
                cell.choiceBtn.hidden = NO;
                cell.choiceBtn.tag = 100*indexPath.section+indexPath.row;
                [cell.choiceBtn addTarget:self action:@selector(choiceInfo:) forControlEvents:64];
                [cell.choiceBtn setTitle:btnTitleArr[indexPath.section][indexPath.row] forState:0];
                cell.contentField.hidden = YES;
                
            }else
            {
                //填入项
                cell.contentField.hidden = NO;
                cell.choiceBtn.hidden = YES;
                
                
                cell.contentField.placeholder = placeArr[indexPath.section][indexPath.row];
                cell.contentField.tag = 10*indexPath.section+indexPath.row;
                cell.contentField.text = infoDic[[self getKeyWithTag:cell.contentField.tag]];
                cell.contentField.delegate = self;
                
            }
        };
    
    if (indexPath.section==0&&(indexPath.row==3||indexPath.row==4)) {
        cell.userInteractionEnabled = NO;
    }
    else
    {
        cell.userInteractionEnabled = YES;
    }

        CSVoidBlock hideBlock = ^(void)
        {
            cell.choiceBtn.hidden = YES;
            cell.contentField.hidden = YES;
            cell.contentLabel.hidden = YES;
        };
        cell.contentField.keyboardType = UIKeyboardTypeDefault;
        switch (indexPath.section) {
            case 0:
                if (indexPath.row==2) {
                    cell.contentField.keyboardType = UIKeyboardTypeNumberPad;
                }
                noHideBlock();
                break;
            case 1:
                noHideBlock();
                break;
            case 2:
            {
                if (indexPath.row==3||indexPath.row==2) {
                    cell.contentField.keyboardType = UIKeyboardTypeNumberPad;
                }
                if (isVolun) {
                    noHideBlock();
                }else
                {
                    hideBlock();
                }
            }
                break;
            case 3:
            {
                if ([self isNeedWritePolicalState]) {
                    noHideBlock();
                }else
                {
                    hideBlock();
                }
            }
                break;
            case 4:
                if (!isAdult) {
                    noHideBlock();
                }else
                {
                    hideBlock();
                }
                break;
        }
        
        
        
        
        
        //志愿者
        
        if (indexPath.section==0&&indexPath.row==10) {
            cell.volunSwitch.hidden = NO;
            cell.choiceBtn.hidden = YES;
            [cell.volunSwitch setOn:isVolun];
            [cell.volunSwitch addTarget:self action:@selector(isVolunteer:) forControlEvents:UIControlEventValueChanged];
        }else cell.volunSwitch.hidden = YES;
        
        
        return cell;
//    }
    
    
}

#pragma mark 是否为志愿者
-(void)isVolunteer:(UISwitch *)sender
{
    if (sender.isOn) {
        isVolun = YES;
    }else
        isVolun = NO;
        
    
    [infoDic setValue:[NSString stringWithFormat:@"%d",isVolun] forKey:@"volunteerFlag"];
    [self.mainTableView reloadData];
}
#pragma mark 选择信息
-(void)choiceInfo:(UIButton *)sender
{
    [self cancelEditing];
    NSArray *arr = nil;
    
    NSInteger sectionNum = sender.tag/100;
    NSInteger rowNum = sender.tag%100;
    
    
    switch (sectionNum) {
        case 0:
        {
            if (rowNum==3) {
                //性别 0-3
                arr = genderArr;
            }
            if (rowNum==7)
            {
                //民族 0-7
                arr =nationArr;
            }else if(rowNum==8)
            {
                //最高学历 0-8
                arr = eduLevelArr;
            }else if(rowNum==9)
            {
                //用户类型 0-9
                arr = userTypeArr;
            }else if(rowNum==11)
            {
                //政治面貌 0-11
                arr = politicalStatusArr;
            }
        }
            break;
        case 1:
        {
            //服务领域 1-0
            arr =severiceTerritoryArr;
        }
            break;
        case 2:
        {
            //服务等级 2-4
            arr = seceiveLevelArr;
        }
            break;

    }

    
    CSResultBlock result = ^(NSString *str)
    {
        [sender setTitle:str forState:0];
        NSMutableArray *mArr = btnTitleArr[sectionNum];
        [mArr replaceObjectAtIndex:rowNum withObject:str];
        [btnTitleArr replaceObjectAtIndex:sectionNum withObject:mArr];
        [infoDic setValue:str forKey:keyArr[sectionNum][rowNum]];
        if (rowNum==11) {
            if ([str isEqualToString:@"团员"]) {
                [sectionTitleArr replaceObjectAtIndex:3 withObject:@"团员基本信息(必填)"];
            }else if([str isEqualToString:@"其它"])
            {
                [sectionTitleArr replaceObjectAtIndex:3 withObject:@"团员/党员基本信息(必填)"];
            }else
            {
                [sectionTitleArr replaceObjectAtIndex:3 withObject:@"党员基本信息(必填)"];
            }
            [self.mainTableView reloadData];
        }
    };
    
    
    NSInteger style = 0;
    BOOL isPush = YES;
    switch (sectionNum) {
        case 0:
        {
            if (rowNum==4) {
                style =PickViewDateThreeChoice;
            }else if (rowNum==5) {
                style =PickViewAeraTwoChoice;
            }else if(rowNum ==6)
            {
                style = PickViewAeraThreeChoice;
            }else
                isPush = NO;
        }
            break;
        case 1:
            if (rowNum==1) {
                style =PickViewAeraThreeChoice;
            }else isPush = NO;
            break;
        case 2:
            if (rowNum!=0) {
                isPush = NO;
            }else style = PickViewDateThreeChoice;
            break;
        case 3:
            if (rowNum!=1) {
                isPush = NO;
            }else style = PickViewDateThreeChoice;
            break;

    }
    
    if (isPush) {
        SignInfoViewController *signInfoVC = [[SignInfoViewController alloc]initWithNibName:@"SignInfoViewController" bundle:nil];
        [signInfoVC setPickViewStyle:style];
        if (style == PickViewDateThreeChoice) {
            //选择日期
            [signInfoVC finishDateEdit:^(NSString *dateStr) {
                result(dateStr);
            }];
        }else
        {
            //选择地区
            [signInfoVC finishPlaceEdit:^(NSString *nameStr, NSString *codeStr) {
                [sender setTitle:nameStr forState:0];
                NSMutableArray *mArr = btnTitleArr[sectionNum];
                [mArr replaceObjectAtIndex:rowNum withObject:nameStr];
                [btnTitleArr replaceObjectAtIndex:sectionNum withObject:mArr];
                [infoDic setValue:codeStr forKey:keyArr[sectionNum][rowNum]];
            }];
        }
        
        
        [self.navigationController pushViewController:signInfoVC animated:YES];
    }else
    {
        //弹出框列表
        MLTableAlert *alert = [MLTableAlert tableAlertWithTitle:@"选择" cancelButtonTitle:@"取消" numberOfRows:^NSInteger (NSInteger section)
                               {
                                   return arr.count;
                               }
                                                       andCells:^UITableViewCell* (MLTableAlert *anAlert, NSIndexPath *indexPath)
                               {
                                   static NSString *CellIdentifier = @"CellIdentifier";
                                   UITableViewCell *cell = [anAlert.table dequeueReusableCellWithIdentifier:CellIdentifier];
                                   if (cell == nil)
                                       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                                   if(sectionNum==0&&rowNum==7)
                                   {
                                       //民族
                                       NSDictionary *strDic = arr[indexPath.row];
                                       cell.textLabel.text =strDic[@"text"];
                                   }else if(sectionNum==0&&rowNum==8)
                                   {
                                       //学历
                                       NSString *str = arr[indexPath.row];
                                       cell.textLabel.text = [[str componentsSeparatedByString:@"-"]lastObject];
                                   }
                                   
                                   else
                                   cell.textLabel.text = arr[indexPath.row];
                                   
                                   return cell;
                               }];
        // Setting custom alert height
        if (arr.count>5) {
            alert.height = 5*44+115;
        }else
        alert.height = arr.count*44+115;
        
        // configure actions to perform
        [alert configureSelectionBlock:^(NSIndexPath *selectedIndex){
            //选择后
            NSString *str = @"";
            
            if(sectionNum==0&&rowNum==7){
                NSDictionary *strDic = arr[selectedIndex.row];
                str =strDic[@"value"];
                NSString *titleStr = strDic[@"text"];
                [sender setTitle:titleStr forState:0];
                NSMutableArray *mArr = btnTitleArr[sectionNum];
                [mArr replaceObjectAtIndex:rowNum withObject:titleStr];
                [btnTitleArr replaceObjectAtIndex:sectionNum withObject:mArr];
                [infoDic setValue:str forKey:keyArr[sectionNum][rowNum]];
            }else if (sectionNum==0&&rowNum==8)
            {
                str = arr[selectedIndex.row];
//                NSString *newStr = arr[]
                NSArray *arr = [str componentsSeparatedByString:@"-"];
                NSString *titleStr = [arr lastObject];
                NSString *infoStr = arr[0];
                [sender setTitle:titleStr forState:0];
                NSMutableArray *mArr = btnTitleArr[sectionNum];
                [mArr replaceObjectAtIndex:rowNum withObject:titleStr];
                [btnTitleArr replaceObjectAtIndex:sectionNum withObject:mArr];
                [infoDic setValue:infoStr forKey:keyArr[sectionNum][rowNum]];
                
            }
            else
            {
                str = arr[selectedIndex.row];
                result(str);
                
            }
            
            
            
            
        } andCompletionBlock:^{
            
        }];
        // show the alert
        [alert show];
    }
    
    
    
}
#pragma mark 根据位置获取字典的key
-(NSString *)getKeyWithTag:(NSInteger)tag
{
    NSInteger sectionNum = tag/10;
    NSInteger rowNum = tag%10;
    NSString *key = keyArr[sectionNum][rowNum];
    return key;
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self cancelEditing];
}
#pragma mark 取消编辑
-(void)cancelEditing
{
    if (editField) {
        [editField resignFirstResponder];
    }
}

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    
//    13690659665
    
    editField = textField;
    
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    NSString *key =[self getKeyWithTag:textField.tag];
    if ([key isEqualToString:@"certificateNo"])
    {
        
        if ([Utils validateIdCard:textField.text])
        {//判断是否为正确的身份证号
            if ([self returnBirthDate:textField.text]) {//判断是否为成年人
                if (!isAdult) {
                    isAdult=YES;
                    [self.mainTableView reloadData];
                }
            }else
            {
                if (isAdult) {
                    isAdult = NO;
                    [self.mainTableView reloadData];
                }
                
            }
        }
        
    
        
    }
    
    [infoDic setValue:textField.text forKey:key];
}
#pragma mark 判断是否成年
-(BOOL)returnBirthDate:(NSString *)idNumStr
{
    NSArray *birthArr = nil;
    if (idNumStr.length==15) {
        birthArr = @[[NSString stringWithFormat:@"19%@",[idNumStr substringWithRange:NSMakeRange(6, 2)]],
                     [idNumStr substringWithRange:NSMakeRange(8, 2)],
                     [idNumStr substringWithRange:NSMakeRange(10, 2)]
                     ];
    }else if(idNumStr.length==18)
    {
        birthArr = @[[idNumStr substringWithRange:NSMakeRange(6, 4)],
                     [idNumStr substringWithRange:NSMakeRange(10, 2)],
                     [idNumStr substringWithRange:NSMakeRange(12, 2)]
                     ];
    }else
        return 0;
    
    
    
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *nowDate = [dateFormatter stringFromDate:[NSDate date]];
    NSArray *nowArr = [nowDate componentsSeparatedByString:@"-"];
    
    if (idNumStr.length==18) {
        NSString *catchStr = [idNumStr substringWithRange:NSMakeRange(16,1)];
        int num = catchStr.intValue%2;
        if (num==0) {
             [infoDic setValue:@"女" forKey:@"gender"];
        }else if(num==1)
        {
            [infoDic setValue:@"男" forKey:@"gender"];
        }
       
        
        NSString *birthdayStr =[NSString stringWithFormat:@"%@-%@-%@",birthArr[0],birthArr[1],birthArr[2]];
        
        NSMutableArray *mArr = btnTitleArr[0];
        [mArr replaceObjectAtIndex:3 withObject:infoDic[@"gender"]];
        [btnTitleArr replaceObjectAtIndex:3 withObject:mArr];
        
        [infoDic setValue:birthdayStr forKey:@"birthday"];
        NSMutableArray *dateArr = btnTitleArr[0];
        [dateArr replaceObjectAtIndex:4 withObject:infoDic[@"birthday"]];
        [btnTitleArr replaceObjectAtIndex:4 withObject:dateArr];
        
        
        NSIndexPath *genderIndexPath = [NSIndexPath indexPathForRow:3 inSection:0];
        NSIndexPath *birthIndexPath = [NSIndexPath indexPathForRow:4 inSection:0];
        
        [self.mainTableView reloadRowsAtIndexPaths:@[genderIndexPath,birthIndexPath] withRowAnimation:UITableViewRowAnimationNone];
    }
    
    
    for (int i=0; i<birthArr.count; i++)
    {
        NSString *nowStr = nowArr[i];
        NSString *birthStr = birthArr[i];
        NSInteger value = nowStr.intValue-birthStr.intValue;
        switch (i) {
            case 0:
            {
                if (value>18) {
                    return 1;
                }else if(value<18)
                {
                    return 0;
                }
            }
                break;
            case 1:
            case 2:
                if (value>0) {
                    return 1;
                }else return 0;
                break;
                
        }
        
    }
    return 1;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
